package com.hu.common.util;


import com.hu.common.domain.base.UserVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;


/**
 * @author 00355760
 */
public class CurrentUserUtil {
    public static UserVO getCurrentUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication == null) {
            return null;
        }
        return (UserVO) authentication.getPrincipal();
    }

    public static String getCurrentUserName() {
        UserVO user = getCurrentUser();
        if (user == null) {
            return StringUtils.EMPTY;
        }
        return user.getUsername();
    }

    public static Long getCurrentUserId() {
        UserVO user = getCurrentUser();
        if (user == null) {
            return (long) 0;
        }
        return user.getId();
    }

    public static String getCurrentRealName() {
        UserVO user = getCurrentUser();
        if (user == null) {
            return StringUtils.EMPTY;
        }
        return user.getRealName();
    }

    public static String getCurrentStaffCode() {
        UserVO user = getCurrentUser();
        if (user == null) {
            return StringUtils.EMPTY;
        }
        return user.getUsername();
    }
}
